<?php
namespace app\admin\controller;

use think\Db;

class Career extends Base{
    /*
     * 说说列表
     */
    public function index(){
        $list = Db::name('career')->where('is_show', 1)->order('id desc')->paginate(12);
        $this->assign('list', $list);
        return $this->fetch();
    }
    /*
     * 添加说说
     */
    public function addCareer(){
        if(IS_POST){
            $career  = I("post.");
            $career['add_time'] = time();
            $result = Db::name('career')->insert($career);
            $data = $result ? array('status' => 1, 'msg' => '添加成功！')
                             : array('status' => 1, 'msg' => '添加失败！');

            ajaxReturn($data);
        }else{
            return $this->fetch('add_career');
        }
    }

    /*
     * 修改说说
     */
    public function editCareer(){
        if(IS_AJAX){
            $id = I('get.id');
            $career = I('post.');
            $result =  Db::name('career')->where(array('id' => $id))->update($career);
            $data = $result ? array('status' => 1, 'msg' => '修改成功！')
                            : array('status' => 0, 'msg' => '修改失败！');

                ajaxReturn($data);
        }else{
            $id = I('get.id');
            $info = Db::name('career')->where(array('id' => $id))->find();
            if($info){
                $this->assign('info', $info);
                return $this->fetch('edit_career');
            }else{
                $this->error('该说说不存在',U('Career/index'));
            }
        }
    }

    /*
     * 删除说说
     */
    public function delCareer(){
        if(IS_AJAX){
            $id = I('get.id');

            $result = Db::name('career')->where('id', 'in', $id)->delete();
            $data = $result ? array('status' => 1, 'msg' => '删除成功')
                            : array('status' => 0, 'msg' => '删除失败');

            ajaxReturn($data);
        }
    }



}